// Author: wsfuyibing <682805@qq.com>
// Date: 2025-06-12

package kind

// CouponState
// 优惠券状态.
type CouponState int

const (
	CouponStateInvisible CouponState = 1 // 不可见(下单时发放, 但是订单未付款)
	CouponStateVisible   CouponState = 2 // 可见(允许正常使用)
	CouponStateExpired   CouponState = 3 // 已过期
	CouponStateUsed      CouponState = 4 // 已使用
	CouponStateDiscarded CouponState = 5 // 弃用(订单退单时撤销)
)

var (
	couponStateTexts = map[CouponState]string{
		CouponStateInvisible: "不可见",
		CouponStateVisible:   "正常",
		CouponStateExpired:   "已过期",
		CouponStateUsed:      "已使用",
		CouponStateDiscarded: "丢弃",
	}

	couponStateFlags = map[CouponState]string{
		CouponStateInvisible: "invisible",
		CouponStateVisible:   "visible",
		CouponStateExpired:   "expired",
		CouponStateUsed:      "used",
		CouponStateDiscarded: "discarded",
	}
)

func CouponStateDict() []map[string]any {
	var res = make([]map[string]any, 0)
	for _, v := range []CouponState{
		CouponStateVisible,
		CouponStateExpired,
		CouponStateUsed,
	} {
		res = append(res, map[string]any{
			"Key":   v,
			"Value": v.Text(),
		})
	}
	return res
}

func (o CouponState) IsVisible() bool { return o == CouponStateVisible }
func (o CouponState) IsExpired() bool { return o == CouponStateExpired }
func (o CouponState) IsUsed() bool    { return o == CouponStateUsed }

func (o CouponState) Flag() string {
	if str, ok := couponStateFlags[o]; ok {
		return str
	}
	return ""
}

func (o CouponState) Text() string {
	if str, ok := couponStateTexts[o]; ok {
		return str
	}
	return ""
}
